﻿<script type="text/javascript">



    function startprogress() {

        var value = $('#p').progressbar('getValue');
        if (value < 100) {
            value += Math.floor(Math.random() * 10);
            $('#p').progressbar('setValue', value);
            setTimeout(arguments.callee, 1500);
        }
    };



    function submitAddForm() { //提交新增方法
        $.GID("btnadd").style.display = "none";
        $.GID("btncancel").style.display = "none";
        var startleng = $("#txtStartNumber").numberbox('getValue');
        var endleng = $("#txtEndNumber").numberbox('getValue');
     
         if (Number(endleng) > 0 && Number(startleng) > 0 && Number(endleng) > Number(startleng)) {
            $.GID("p").style.display = "block";
            $('#p').progressbar('setValue', 0);


            //2016-4-17 新增判断 发票号是否在已审批的发票号中
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/IM/I_InvoiceApproval/IFExistInvoice")',
                data:
                    {
                        txtStartNumber: $('#txtStartNumber').numberbox("getValue"),
                        txtEndNumber: $('#txtEndNumber').numberbox("getValue")


                    },
                dataType: "json",
                success: function (jsData) {

                    if (!jsData) {


                        $('#formSubmit').form('submit', {
                            url: '@Url.Content("~/IM/I_InvoiceApproval/SaveApprovalInfo")',
                            //queryParams: {
                            //    ambid: ambCode
                            //},
                            onSubmit: function () {
                                return $(this).form('validate');
                            },

                            success: function (data) {
                                var jsData = $.parseJSON(data);
                                $.GID("btnadd").style.display = "block";
                                $.GID("btncancel").style.display = "block";

                                $.showMsg(jsData.Message, "系统提示", function () { });
                                $('#AccidentDetailDialog').dialog('close');
                                $('#gridApprovalList').datagrid('reload');
                                ClearForm();


                            }
                        });
                    }
                    else {
                        $.messager.alert('警告', ' 已经存在审批的发票号,请重新填写!');
                        $.GID("btnadd").style.display = "block";
                        $.GID("btncancel").style.display = "block";
                        $('#AccidentDetailDialog').dialog('close');
                        ClearForm();


                    }

                }
            });

            startprogress();


        } else {
            $.messager.alert('警告', '请正确填写发票号码,请重新填写!');
            $.GID("btnadd").style.display = "block";
            $.GID("btncancel").style.display = "block";
        }
    }


    function cancelDialog() {
        ClearForm();
        $('#AccidentDetailDialog').dialog('colse');
    }

    function ClearForm() {
        //$('#txtCenterCode').textbox('clear');
        $('#txtStationCode').textbox('clear');
        $('#txtApplyUserName').textbox('clear');
        $('#txtApplyCount').textbox('clear');
        $('#txtStartNumber').numberbox('clear');
        $('#txtEndNumber').numberbox('clear');
        $('#txtApprovalCount').textbox('clear');
        $('#txtRemark2').combobox('clear');

    }


    function getChargeSum(cid) {
        $(cid).numberbox({
            onChange: function (newV, oldV) {
                getChargeTotal();
            }
        });
    }
    //发票号算多少个
    function getChargeTotal() {
        var a = $('#txtEndNumber').numberbox('getValue');
        var b = $('#txtStartNumber').numberbox('getValue');
        var KMTotal = Number(a) - Number(b) + 1;
        if (KMTotal <= 0) {
            $('#txtApprovalCount').textbox('setValue', "0");
        }
        else { $('#txtApprovalCount').textbox('setValue', KMTotal); }
    }




</script>

<div id="AccidentDetailDialog" class="easyui-dialog" title="审批发票" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width: 800px; height: auto; padding: 5px;">
    <form id="formSubmit" method="post">
        <input name="ApplyID" id="txtApplyID" type="hidden">

        <div style="width: 99%; height: auto;">
            <table style="width:99%;height:auto;">
                <tr>
                    <td valign="top">

                        <div class="easyui-accordion" style="width: 99%; height: auto;">
                            <div title="审批发票" data-options="iconCls:'icon-save'" style="overflow:auto;padding:5px;">
                                <table border="0">

                                    <tr>

                                        @*<td style="width:75px" align="right">分中心：</td>
                                        <td style="width:145px" align="left" valign="middle">
                                            <input class="easyui-textbox" style="width: 120px" name="CenterCode" id="txtCenterCode" data-options="panelHeight:'auto'">
                                        </td>*@
                                        <td style="width:75px" align="right">分站：</td>
                                        <td style="width:145px" align="left" valign="middle">
                                            <input class="easyui-textbox" style="width: 120px" name="CenterCode" id="txtStationCode" data-options="panelHeight:'auto'">
                                        </td>
                                        <td style="width:50px" align="right">  申领人：</td>
                                        <td style="width:125px">
                                            <input class="easyui-textbox" style="width: 120px" name="ApplyUserName" id="txtApplyUserName">

                                        </td>
                                        <td style="width:75px" align="right">  需求：</td>
                                        <td style="width:125px">
                                            <input class="easyui-textbox" style="width: 80px" name="ApplyCount" id="txtApplyCount">
                                            张
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            发票号起止：
                                        </td>
                                        <td>
                                            <input class="easyui-numberbox" style="width: 150px" name="StartNumber" id="txtStartNumber" data-options="required:true">
                                        </td>

                                        <td align="center">
                                            ----
                                        </td>
                                        <td>
                                            <input class="easyui-numberbox" style="width: 150px" name="EndNumber" id="txtEndNumber" data-options="required:true">
                                        </td>

                                        <td align="right">
                                            共计：
                                        </td>
                                        <td>
                                            <input name="ApprovalCount" id="txtApprovalCount" class="easyui-textbox" style="width: 80px" data-options="required:true" />
                                            张
                                        </td>
                                    </tr>

                                    <tr>
                                        <td align="right">
                                            备注：
                                        </td>
                                        <td colspan="5">
                                            <input class="easyui-textbox" style="width: 500px" name="Remark2" id="txtRemark2" data-options="panelHeight:'auto'">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right" colspan="3">
                                            <a href="javascript:void(0)" id="btnadd" style="width:80px;height:25px" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="submitAddForm();">批准申领</a>
                                        </td>
                                        <td align="left" colspan="3">
                                            <a href="javascript:void(0)" id="btncancel" style="width:80px;height:25px" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="cancelDialog();">取消</a>
                                        </td>
                                    </tr>
                                    <tr>

                                        <td colspan="6">
                                            <div id="p" class="easyui-progressbar" style="width:600px;"></div>

                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </td>

                </tr>
            </table>
        </div>
    </form>
</div>
